import config from '../config'
import CanvasAbstract from './CanvasAbstract'
import TankModel from '../model/tank'
import position from '../service/position'
class Tank extends CanvasAbstract implements ICanvas {
  intervalId = 0
  num(): number {
    return config.tank.num
  }
  model(): ModelConstruct {
    return TankModel
  }
  rander(): void {
    this.createModels()
    super.renderModel()
    this.intervalId = setInterval(() => this.renderModel(), config.timeout)
  }

  public renderModel() {
    this.ctx.clearRect(0, 0, config.canvas.width, config.canvas.height)
    super.renderModel()
    // this.models.forEach(model => {
    //   model.render()
    //   this.canvas.drawImage(model.image(), model.x, model.y, config.model.width, config.model.height)
    // })
  }
  public stop() {
    clearInterval(this.intervalId)
  }
  protected createModels(): void {
    for (let i = 0; i < this.num(); i++) {
      const pos = position.position()
      const model = this.model()
      const instance = new model(pos.x, 0)
      this.models.push(instance)
    }
  }
}

export default new Tank('tank')
